/**
 * 
 */
package net.kong.sns.rest.client.model;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author <a href="mailto:jolestar@gmail.com">Wang Yuanmin</a>
 */
public class LoginResult extends AbstractJsonAppObject {

    /**
     * SessionKey
     */
    private String sessionKey;
    /**
     * 用户基本信息
     */
    private UserInfo userInfo;

    public enum Field {
        session_key, user_info;

        @Override
        public String toString() {
            return name().toLowerCase();
        }
        public static Set<String> valuesSet() {
            Field[] fields = Field.values();
            Set<String> strFields = new HashSet<String>();
            for(int i=0;i<fields.length;i++) {
                strFields.add(fields[i].toString());
            }
            return strFields;
        }
    }

    public String getSessionKey() {
        return sessionKey;
    }

    public void setSessionKey(String sessionKey) {
        this.sessionKey = sessionKey;
    }

    public UserInfo getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

    /*
     * (non-Javadoc)
     * @see net.kong.sns.rest.client.model.AbstractJsonAppObject#processJsonObject(java.util.Map)
     */
    @Override
    protected void processJsonObject(Map<String, Object> stringObjectMap) {
        if (stringObjectMap != null) {
            Set<String> fields = getInitializedFields();
            for (String fieldName : fields) {
                Object o = (Object) stringObjectMap.get(fieldName);
                if (o != null) {
                    if (fieldName.equals(Field.session_key.toString())) {
                        this.sessionKey = o.toString();
                    }
                    else if (fieldName.equals(Field.user_info.toString())) {
                        UserInfoImpl userImpl = new UserInfoImpl();
                        userImpl.initialize((Map<String, Object>) o, UserInfo.Field.valuesSet());
                        this.userInfo = userImpl;
                    }
                }
            }
        }
    }

}
